#ifndef __PLAYER_H__
#define __PLAYER_H__
#include <string>
#include <memory>

#include "game/card.h"
#include "socket.h"
#include "singleton.h"
#include "proto/message.pb.h"

class Player
{
public:
    typedef std::shared_ptr<Player> ptr;

    Player(int fd)
    {
        m_socket = std::make_shared<Socket>(fd);
    }

    Socket::ptr& GetSocket() { return m_socket; }

    void SetId(int id)
    {
        m_id = id;
    }

    int GetId() const
    {
        return m_id;
    }

    void SetName(const std::string& name)
    {
        m_name = name;
    }

    const std::string& GetName() const
    {
        return m_name;
    }

    const std::string& GetIconName() const
    {
        return m_iconName;
    }

    void SetIconName(const std::string iconName)
    {
        m_iconName = iconName;
    }

    proto::SeatPosition GetSeatPosition()
    {
        return m_seatPosition;
    }

    void SetPosition(proto::SeatPosition position)
    {
        m_seatPosition = position;
    }

    proto::CardType GetCardType()
    {
        return m_cardType;
    }

    void SetCardType(proto::CardType cardType)
    {
        m_cardType = cardType;
    }

    int GetStakesSum()
    {
        return m_stakesSum;
    }

    void SetStakesSum(int stake)
    {
        m_stakesSum += stake;
    }
    //添加卡牌
    void AddCard(Card::ptr card)
    {
        m_cards.push_back(card);
    }

    std::vector<Card::ptr>& GetCards()
    {
        return m_cards;
    }

    bool operator==(const Player::ptr& player);
private:
    int m_id;
    int m_stakesSum;
    std::vector<Card::ptr> m_cards;
    proto::CardType m_cardType;
    std::string m_iconName;
    std::string m_name;
    proto::SeatPosition m_seatPosition;
    Socket::ptr m_socket;
};

class PlayerManager
{
public:
    typedef std::shared_ptr<PlayerManager> ptr;

    //用一个有效的文件描述符初始化得到一个玩家
    Player::ptr get(int fd);

    //移除某玩家
    void del(int fd);
private:
    //文件描述符到socket的映射
    std::map<int, Player::ptr> m_players;
};

typedef Singleton<PlayerManager> PlayerMgr;

#endif // !__PLAYER_H__